<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Sets mysqli error reporting mode</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mysqli-driver.embedded-server-start.html">« mysqli_driver::embedded_server_start</a></li>
      <li style="float: right;"><a href="class.mysqli-warning.html">MySQLi_Warning »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.mysqli-driver.html">MySQLi_Driver</a></li>
    <li>Sets mysqli error reporting mode</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mysqli-driver.report-mode" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysqli_driver::$report_mode</h1>
  <h1 class="refname">mysqli_report</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mysqli_driver::$report_mode</span> -- <span class="refname">mysqli_report</span> &mdash; <span class="dc-title">Sets mysqli error reporting mode</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mysqli-driver.report-mode-description">
  <h3 class="title">说明</h3>
  <p class="para">面向对象风格</p>
  <div class="fieldsynopsis">
   <span class="type">int</span> <var class="varname"><a href="mysqli-driver.report-mode.html">$mysqli_driver-&gt;report_mode</a></var>;</div>

  <p class="para">过程化风格</p>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><a href="function.mysqli-report.html" class="methodname">mysqli_report</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Depending on the flags, it sets mysqli error reporting mode to exception, warning or none.  
   When set to <strong><code>MYSQLI_REPORT_ALL</code></strong> or <strong><code>MYSQLI_REPORT_INDEX</code></strong> 
   it will also inform about queries that don&#039;t use an index (or use a bad index).
  </p>
  <p class="para">
   As of PHP 8.1.0, the default setting is <code class="literal">MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT</code>.
   Previously, it was <strong><code>MYSQLI_REPORT_OFF</code></strong>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-mysqli-driver.report-mode-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">flags</code></dt>

     <dd>

      <p class="para">
       <table id="mysqli-driver.report-mode.parameters" class="doctable table">
        <caption><strong>Supported flags</strong></caption>
        
         <thead>
          <tr>
           <th>Name</th>
           <th>Description</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td><strong><code>MYSQLI_REPORT_OFF</code></strong></td>
           <td>Turns reporting off</td>
          </tr>

          <tr>
           <td><strong><code>MYSQLI_REPORT_ERROR</code></strong></td>
           <td>Report errors from mysqli function calls</td>
          </tr>

          <tr>
           <td><strong><code>MYSQLI_REPORT_STRICT</code></strong></td>
           <td>
            Throw <span class="classname"><a href="class.mysqli-sql-exception.html" class="classname">mysqli_sql_exception</a></span> for errors
            instead of warnings
           </td>
          </tr>

          <tr>
           <td><strong><code>MYSQLI_REPORT_INDEX</code></strong></td>
           <td>Report if no index or bad index was used in a query</td>
          </tr>

          <tr>
           <td><strong><code>MYSQLI_REPORT_ALL</code></strong></td>
           <td>Set all options (report all)</td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mysqli-driver.report-mode-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns <strong><code>true</code></strong>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-mysqli-driver.report-mode-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.1.0</td>
      <td>
       The default value is now <code class="literal">MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT</code>.
       Previously, it was <strong><code>MYSQLI_REPORT_OFF</code></strong>.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-mysqli-driver.report-mode-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1541">
   <p><strong>示例 #1 面向对象风格</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;activate&nbsp;reporting&nbsp;*/<br /></span><span style="color: #0000BB">$driver&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli_driver</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$driver</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">report_mode&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">MYSQLI_REPORT_ALL</span><span style="color: #007700">;<br /><br />try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;if&nbsp;the&nbsp;connection&nbsp;fails,&nbsp;a&nbsp;mysqli_sql_exception&nbsp;will&nbsp;be&nbsp;thrown&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_user"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_db"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;this&nbsp;query&nbsp;should&nbsp;report&nbsp;an&nbsp;error&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;Name&nbsp;FROM&nbsp;Nonexistingtable&nbsp;WHERE&nbsp;population&nbsp;&gt;&nbsp;50000"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;this&nbsp;query&nbsp;should&nbsp;report&nbsp;a&nbsp;bad&nbsp;index&nbsp;if&nbsp;the&nbsp;column&nbsp;population&nbsp;doesn't&nbsp;have&nbsp;an&nbsp;index&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;Name&nbsp;FROM&nbsp;City&nbsp;WHERE&nbsp;population&nbsp;&gt;&nbsp;50000"</span><span style="color: #007700">);<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">mysqli_sql_exception&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">error_log</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">__toString</span><span style="color: #007700">());<br />}</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="example-1542">
   <p><strong>示例 #2 过程化风格</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;activate&nbsp;reporting&nbsp;*/<br /></span><span style="color: #0000BB">mysqli_report</span><span style="color: #007700">(</span><span style="color: #0000BB">MYSQLI_REPORT_ALL</span><span style="color: #007700">);<br /><br />try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;if&nbsp;the&nbsp;connection&nbsp;fails,&nbsp;a&nbsp;mysqli_sql_exception&nbsp;will&nbsp;be&nbsp;thrown&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysqli_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_user"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_db"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;this&nbsp;query&nbsp;should&nbsp;report&nbsp;an&nbsp;error&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysqli_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;Name&nbsp;FROM&nbsp;Nonexistingtable&nbsp;WHERE&nbsp;population&nbsp;&gt;&nbsp;50000"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;this&nbsp;query&nbsp;should&nbsp;report&nbsp;a&nbsp;bad&nbsp;index&nbsp;if&nbsp;the&nbsp;column&nbsp;population&nbsp;doesn't&nbsp;have&nbsp;an&nbsp;index&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysqli_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;Name&nbsp;FROM&nbsp;City&nbsp;WHERE&nbsp;population&nbsp;&gt;&nbsp;50000"</span><span style="color: #007700">);<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">mysqli_sql_exception&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">error_log</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">__toString</span><span style="color: #007700">());<br />}</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="example-1543">
   <p><strong>示例 #3 Error reporting except bad index errors</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;activate&nbsp;reporting&nbsp;*/<br /></span><span style="color: #0000BB">mysqli_report</span><span style="color: #007700">(</span><span style="color: #0000BB">MYSQLI_REPORT_ERROR&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">MYSQLI_REPORT_STRICT</span><span style="color: #007700">);<br /><br />try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;if&nbsp;the&nbsp;connection&nbsp;fails,&nbsp;a&nbsp;mysqli_sql_exception&nbsp;will&nbsp;be&nbsp;thrown&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_user"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_db"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;this&nbsp;query&nbsp;should&nbsp;report&nbsp;an&nbsp;error&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;Name&nbsp;FROM&nbsp;Nonexistingtable&nbsp;WHERE&nbsp;population&nbsp;&gt;&nbsp;50000"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;this&nbsp;WILL&nbsp;NOT&nbsp;report&nbsp;any&nbsp;errors&nbsp;even&nbsp;if&nbsp;index&nbsp;is&nbsp;not&nbsp;available&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;Name&nbsp;FROM&nbsp;City&nbsp;WHERE&nbsp;population&nbsp;&gt;&nbsp;50000"</span><span style="color: #007700">);<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">mysqli_sql_exception&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">error_log</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">__toString</span><span style="color: #007700">());<br />}</span>
</span>
</code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-mysqli-driver.report-mode-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="classname"><a href="class.mysqli-sql-exception.html" class="classname">mysqli_sql_exception</a></span></li>
    <li class="member"><span class="function"><a href="function.set-exception-handler.html" class="function" rel="rdfs-seeAlso">set_exception_handler()</a> - 设置用户自定义的异常处理函数</span></li>
    <li class="member"><span class="function"><a href="function.error-reporting.html" class="function" rel="rdfs-seeAlso">error_reporting()</a> - 设置应该报告何种 PHP 错误</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>